var video = document.getElementsByTagName("video")[0];
var playControl = document.getElementsByClassName("play_control-btn")[0];
var playBox = document.getElementsByClassName('v-play-box')[0];
var playControll = document.getElementsByClassName('control_box')[0];
var inLock = false;
var timer = null;

// 暂停播放
playControl.onclick = function(){
     if(video.paused){
           video.play();
           this.className = 'play_control-btn paused';
           setSecToExec();
     }else{
           video.pause();
           this.className = 'play_control-btn play';
           clearInterval(timer);
     }
}


/**
 * 呼出控制菜单
 */
playBox.onclick = function(){
     inLock = true;
     playControll.style.bottom = 0;
     setTimeout(function(){
          inLock = false;
     },5000)
}

var htimer = null;
toHidenLayer();
/**
 * 隐藏控制层
 */
function toHidenLayer(){
    htimer = setInterval(function(){
         console.log(inLock);
         if(!inLock){
             playControll.style.bottom = -48+"px";
         }
    },1000)
}

/**
 * 进度条监听
 */
function listenProgressBar(num){
     // 获取进度条对象
     var vprogress_bar = document.getElementsByClassName('v-progress_bar')[0].getElementsByTagName('p')[0];
     vprogress_bar.style.width = num*100+'%';
}
//执行
setSecToExec();
/**
 * 每秒开始执行
 */
function setSecToExec(){
     timer = setInterval(function(){
           var allTime = video.duration; // 总时间
           var current = video.currentTime;
           var scale = current/allTime;
           listenProgressBar(scale)
           listenTime(current);
     },1000)
}

/**
 * 时间监听
 */
function listenTime(current){
    var time = document.getElementsByClassName('v_time')[0];
    time.innerHTML = data_format(current);
}

//时间格式化函数
function data_format(time){
    var h,s,m,remain;
    h= fill_zero(parseInt(time/3600));
    remain = time%3600;
    m = fill_zero(parseInt(remain/60));
    remain = fill_zero(parseInt(remain%60));
    s = remain;
    return m+":"+s;
}
//补零函数
function fill_zero(num){
    if(num<=9){

        return "0"+num;

    }else{
        return ""+num;
    }
}